﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Incendios0_1.sms;

namespace Incendios0_1.user_managment
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void button_delet_user_Click(object sender, RoutedEventArgs e)
        {
            delete();
        }

        private void button_cancel_delete_user_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            delete();
        }

        private void delete()
        {
            if (textBox1.Text == "admin")
            {
                Microsoft.Windows.Controls.MessageBox.Show("Es imposible borrar el usuario admin", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            Users user = UserControler.SearchUser(textBox1.Text);
            if (user == null)
            {
                Microsoft.Windows.Controls.MessageBox.Show("El usuario no existe", "No encontrado", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                MessageBoxResult result = Microsoft.Windows.Controls.MessageBox.Show("Realmente desea borrar el usuario " + user.Username, "No encontrado", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    UserControler.Delete(user);
                    Contacts contact = ContactControler.SearchContactByUser(user.UserId);
                    if (contact != null)
                    {
                        ContactControler.Delete(contact);
                    }
                }
            }
        }
    }
}
